<template>
    <div class="favor">
        <nav-bar left-text="旅途">
            <template #title>
                <van-tabs v-model:active="active" type="card" shrink>
                    <van-tab v-for="item in titles" :title="item" />
                </van-tabs>
            </template>
        </nav-bar>

        <div class="favor" v-if="active === 0">
            <van-tabs v-model:active="activeName">
                <van-tab title="房屋">
                    <div class="content">
                        <template v-for="(item, index) in favorList">
                            <search-list-item :item-data="item" />
                        </template>
                    </div>
                </van-tab>
                <van-tab title="房东">
                    <div v-if="landlordList.length" class="list"></div>
                    <div v-else class="no-data">
                        <img class="icon-no-data" src="@/assets/img/favor/empty_favorite.44731802.png" alt="">
                        <div class="name">暂无收藏</div>
                        <div class="desp">
                            点击
                            <img src="@/assets/img/favor/favor.png" alt="">
                            即可收藏对应的房东
                        </div>
                        <button class="btn" @click="handleBtnClick">随便去逛逛</button>
                    </div>
                </van-tab>
            </van-tabs>
        </div>
        <div class="history" v-if="active === 1">
            <div class="content">
                <template v-for="(item, index) in historyList">
                    <search-list-item :item-data="item" />
                </template>
            </div>
        </div>
    </div>
</template>


<script setup>
import useFavorStore from '@/stores/modules/favor';
import searchListItem from '@/components/search-list-item/search-list-item.vue';
import navBar from '@/components/nav-bar/nav-bar.vue';
import { storeToRefs } from 'pinia';
import { ref } from 'vue';
import router from '@/router';

const active = ref(0)
const titles = ["我的收藏", "浏览历史"]
const activeName = ref(0)
const landlordList = ref([])

// 获取数据
const favorStore = useFavorStore()
favorStore.fetchFavorListData()
favorStore.fetchHistoryListData()
const { favorList, historyList } = storeToRefs(favorStore)
console.log(favorList, historyList);

// 点击事件
const handleBtnClick = () => {
    router.push("/")
}

</script>


<style lang="less" scoped>
.content {
    padding: 10px 20px 55px 20px;
}

.left {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;

    .icon-left-arrow {
        display: inline-block;
        background: url(@/assets/img/common/icon_nav_back.png) 0 0/ 100% 100%;
        width: 8px;
        height: 15px;
    }

    .left-text {
        color: var(--primary-color);
        margin-left: 8px;
        font-weight: 700;
    }
}



.no-data {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;

    .icon-no-data {
        width: 100%;
    }

    .name {
        font-size: 17px;
        font-weight: 500;
        color: #333;
        line-height: 27px;
    }

    .desp {
        color: #666;
        line-height: 27px;
        margin: 7px auto 36px;

        img {
            position: relative;
            top: 6px;
            width: 12px;
        }
    }

    .btn {
        padding: 0 38px;
        height: 40px;
        line-height: 40px;
        background: var(--primary-color);
        border: none;
        border-radius: 15px;
        color: #fff;
        font-size: 16px;

    }
}
</style>